--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_izayoi_sakuya = General:new(extension, "hy_izayoi_sakuya", "jin_k", 3, 3, General.Female)
    local virtual_time = fk.CreateSkill {
        name = "virtual_time",
    }
    virtual_time:addEffect(fk.GameStart, {
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(self) then
                return false
            end
            return true
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:addPlayerMark(player, "@virtual_time", 1)
            room:drawCards(player, 1, virtual_time.name)
            player:setSkillUseHistory(virtual_time.name, 0, Player.HistoryTurn)
        end,
    })
    virtual_time:addEffect(fk.CardRespondFinished, {
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(self) then
                return false
            end
            return player:usedSkillTimes(virtual_time.name, Player.HistoryTurn) < 1 and data.from ~= player and data.responseToEvent and data.responseToEvent.from and data.responseToEvent.from == player
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:addPlayerMark(player, "@virtual_time", 1)
            room:drawCards(player, 1, virtual_time.name)
        end,
    })
    virtual_time:addEffect(fk.CardUseFinished, {
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(self) then
                return false
            end
            return player:usedSkillTimes(virtual_time.name, Player.HistoryTurn) < 1 and data.from ~= player and data.responseToEvent and data.responseToEvent.from == player
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:addPlayerMark(player, "@virtual_time", 1)
            room:drawCards(player, 1, virtual_time.name)
        end,
    })
    local waiting_ghost = fk.CreateSkill {
        name = "waiting_ghost",
    }
    waiting_ghost:addEffect("active", {
        target_num = 1,
        card_num = 0,
        target_filter = function(self, player, to_select, selected, selected_cards)
            return #selected == 0 and not to_select:isNude()
        end,
        card_filter = Util.FalseFunc,
        can_use = function(self, player)
            return player:usedSkillTimes(waiting_ghost.name, Player.HistoryPhase) < 1 and player:getMark("waiting_ghost_disable-phase") == 0
        end,
        prompt = function(self, selected_cards, selected_targets)
            return "waiting_ghost_prompt:::" .. Self:getMark("@virtual_time")
        end,
        on_use = function(self, room, cardUseEvent)
            local player = cardUseEvent.from
            local target = cardUseEvent.tos[1]
            local max = math.max(player:getMark("@virtual_time"), 1)
            local cards = room:askToChooseCards(player, {
                target = target,
                min = 1,
                max = max,
                flag = "he",
                skill_name = waiting_ghost.name,
                prompt = "waiting_ghost_prompt_card::" .. target.id .. ":" .. tostring(max)
            })
            target:addToPile("$waiting_ghost", cards, false, waiting_ghost.name, player)
            room:setPlayerMark(player, "phantom_operate_disable-phase", 1)
        end
    })
    waiting_ghost:addEffect(fk.EventPhaseStart, {
        can_trigger = function(self, event, target, player, data)
            local room = player.room
            if not player:hasSkill(self) then
                return false
            end
            if table.every(room.alive_players, function(t)
                    return #t:getPile("$waiting_ghost") == 0
                end) then
                return false
            end
            return target == player and target.phase == Player.Start
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            for _, t in pairs(room.alive_players) do
                local cards = t:getPile("$waiting_ghost")
                room:obtainCard(t, cards, false, fk.ReasonPrey, t, waiting_ghost.name)
            end
        end
    })
    waiting_ghost:addEffect(fk.Damaged, {
        can_trigger = function(self, event, target, player, data)
            local room = player.room
            if not player:hasSkill(self) then
                return false
            end
            if table.every(room.alive_players, function(t)
                    return #t:getPile("$waiting_ghost") == 0
                end) then
                return false
            end
            return target == player
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            for _, t in pairs(room.alive_players) do
                local cards = t:getPile("$waiting_ghost")
                room:obtainCard(t, cards, false, fk.ReasonPrey, t, waiting_ghost.name)
            end
        end
    })
    local phantom_operate = fk.CreateSkill {
        name = "phantom_operate",
    }
    phantom_operate:addEffect("active", {
        target_filter = Util.FalseFunc,
        card_filter = function(self, player, to_select, selected)
            return #selected < player:getMark("@virtual_time") and table.contains(player:getCardIds("he"), to_select)
        end,
        feasible = function(self, player, selected, selected_cards, card)
            return #selected_cards == player:getMark("@virtual_time")
        end,
        can_use = function(self, player)
            return player:usedSkillTimes(phantom_operate.name, Player.HistoryPhase) < 1 and player:getMark("phantom_operate_disable-phase") == 0
        end,
        prompt = function(self, player, selected_cards, selected_targets)
            return "phantom_operate_prompt:::" .. player:getMark("@virtual_time")
        end,
        on_use = function(self, room, cardUseEvent)
            local player = cardUseEvent.from
            room:throwCard(cardUseEvent.cards, phantom_operate.name, player, player)
            for i = 1, 2, 1 do
                local use = room:askToUseVirtualCard(player, {
                    name = "slash",
                    skill_name = phantom_operate.name,
                    prompt = "phantom_operate_prompt_slash",
                    extra_data = {
                        bypass_distances = true,
                        bypass_times = true,
                        extraUse = false,
                    }
                })
                if not use then
                    break
                end
            end
            room:setPlayerMark(player, "waiting_ghost_disable-phase", 1)
        end,
    })
    extension:loadSkillSkels { virtual_time, waiting_ghost, phantom_operate }
    hy_izayoi_sakuya:addSkill("virtual_time")
    hy_izayoi_sakuya:addSkill("waiting_ghost")
    hy_izayoi_sakuya:addSkill("phantom_operate")
    Fk:loadTranslationTable {
        ["hy_izayoi_sakuya"] = "十六夜咲夜",
        ["#hy_izayoi_sakuya"] = "魔术时刻",
        ["designer:hy_izayoi_sakuya"] = "黑曜人形",
        ["illustrator:hy_izayoi_sakuya"] = "咲崎さきｐ",
        ["cv:hy_izayoi_sakuya"] = "",

        ["virtual_time"] = "虚时",
        [":virtual_time"] = "游戏开始时，你获得1枚“时”标记并摸一张牌。每回合限一次，其他角色响应你使用的牌后，你获得1枚“时”并摸一张牌。",
        ["@virtual_time"] = "时",

        ["waiting_ghost"] = "滞影",
        ["#waiting_ghost_recover"] = "滞影",
        [":waiting_ghost"] = "出牌阶段限一次，你可以将一名角色一至X张牌扣置于其武将牌上（X为你的“时”的数量且至少为1），然后本阶段你不能发动“幻操”。准备阶段或你受到伤害后，其获得这些牌。",
        ["$waiting_ghost"] = "滞影",
        ["waiting_ghost_prompt"] = "滞影：你可以扣置一名角色1至%arg张牌",
        ["waiting_ghost_prompt_card"] = "滞影：你可以扣置%dest1至%arg张牌",

        ["phantom_operate"] = "幻操",
        [":phantom_operate"] = "出牌阶段限一次，你可以弃置X张牌并视为使用至多两张无距离次数限制的【杀】（X为你的“时”的数量），然后本阶段你不能发动“滞影”。",
        ["@phantom_operate_record-phase"] = "幻操",
        ["phantom_operate_prompt"] = "幻操：你可以弃置%arg张牌",
        ["phantom_operate_prompt_slash"] = "幻操：你可以视为使用一张【杀】",
    }
end
